package com.xfhy.wallpaperdemo;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Bundle;

import com.xfhy.wallpaperdemo.live.DaemonHelper;
import com.xfhy.wallpaperdemo.lock.LockScreenReceiver;
import com.xfhy.wallpaperdemo.lock.NotifyService;
import com.xfhy.wallpaperdemo.live.pk;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * @author : xfhy
 * Create time : 2020/10/29 11:18
 * Description :
 */
public class MyApplication extends Application {

    public static Context sContext;

    @Override
    public void attachBaseContext(Context context) {
        super.attachBaseContext(context);
        sContext = this;

        DaemonHelper.init(this);
    }

    public static Activity sActivity;

    @Override
    public void onCreate() {
        super.onCreate();
        sContext = this;

        NotifyService.startToolNoti(MyApplication.sContext);
        initLock();
        pk.getInstance().start();

        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
                sActivity = activity;
            }

            @Override
            public void onActivityStarted(@NonNull Activity activity) {

            }

            @Override
            public void onActivityResumed(@NonNull Activity activity) {

            }

            @Override
            public void onActivityPaused(@NonNull Activity activity) {

            }

            @Override
            public void onActivityStopped(@NonNull Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(@NonNull Activity activity) {

            }
        });
    }

    public static void initLock() {
        LockScreenReceiver a = new LockScreenReceiver();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.SCREEN_ON");
        intentFilter.addAction("android.intent.action.SCREEN_OFF");
        intentFilter.addAction("android.intent.action.USER_PRESENT");
        intentFilter.addAction("android.intent.action.CLOSE_SYSTEM_DIALOGS");
        intentFilter.addAction("xx.full_nc");
        MyApplication.sContext.registerReceiver(a, intentFilter);
        pk.getInstance().addCallback(a);
    }

}

